<?php
/**
 * Klasse zum erstellen eines Grid-Row
 *
 * @author		Joachim Ruf, Loresoft Software (http://www.loresoft.de)
 * @license		New BSD License
 * @version		Class for Bootstrap v2.3.2
 *
 * */


Class Bootstrap_Grid_Row
{
	private $arrElement		= array();
	private $arrParam		= array();
	private $fluid			= false;

	/**
	 * */
	function __construct ($_fluid = false, array $_arrParam = array()) {
		if (!is_bool($_fluid)) {
			return NULL;
		}
		if (!is_array($_arrParam)) {
			return NULL;
		}

		$this->fluid	= $_fluid;
		$this->arrParam	= $_arrParam;
	}


	private function getParameter ($_class, array $_arrParam) {
		$result	= NULL;

		if (isset($_arrParam['class'])) { // Class-Parameter verbinden
			$_arrParam['class']	= $_arrParam['class'].' '.$_class;
		} else {
			$_arrParam['class']	= $_class;
		}

		foreach ($_arrParam as $key => $val) {
			$result	.= ' '.$key.'="'.$val.'"';
		}

		return $result;
	}


	/**
	 * Liefert eine Zeile zurueck.
	 * @param int $_size		: Breite {1-12}
	 * @param string $_content	: Auszugebender Content
	 * @return Bootstrap_Grid_Row
	 * */
	public function addColumn ($_size, $_content = NULL, $_offset = NULL, array $_arrParam = array()) {
		if (!is_numeric($_size)) {
			trigger_error('addColum(int, string), first parameter have to be a numeric value', E_USER_WARNING);
		}

		return $this->arrElement[] = new Bootstrap_Grid_Column($_size, $_content, $_offset, $_arrParam);
	}


	/**
	 * Liefert eine Zeile zurueck.
	 * @param int $i	: Auszugebende Zeile
	 * @return Yapary_Form_Formular_Element
	 * */
	public function getColumn ($i) {
		if (!isset($this->arrElement[$i])) {
			return NULL;
		}

		return $this->arrElement[$i];
	}


	/**
	 * @desc Liefert alle Zeilen zurueck.
	 * @return Yapary_Form_Formular_Element[]
	 * */
	public function getColumnList () {
		return $this->arrElement;
	}


	/**
	 * Loescht einen Eintrag.
	 * @param string $id	: Zu loeschender Eintrag
	 * @return bool
	 * */
	public function deleteColumn ($i) {
		if (!isset($this->arrElement[$i])) {
			return false;
		}

		unset($this->arrElement[$i]);
		return true;
	}


	/**
	 * @desc Gibt ein Grid-Row aus.
	 * @return string
	 * */
	public function display() {
		$result	= NULL;
		$row	= ($this->fluid === true) ? 'row-fluid' : 'row';

		if (count($this->arrElement)) {
			/* @var $oColumn Bootstrap_Grid_Column */
			foreach ($this->arrElement as $key => $oColumn) {
				$result .=	$oColumn->display();
			}
		}

		return '<div'.$this->getParameter('row', $this->arrParam).'>
					'.$result.'
				</div>';
	}


}


?>